package ch.unizh.ifi.ailab.gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import org.apache.log4j.Logger;

import ch.unizh.ifi.ailab.camera.Camera;
import ch.unizh.ifi.ailab.camera.ImagePanel;
import ch.unizh.ifi.ailab.config.LocalizationSettings;
import ch.unizh.ifi.ailab.config.ProgramSettings;
import ch.unizh.ifi.ailab.config.PropertyFileFilter;
import ch.unizh.ifi.ailab.suitcase.Suitcase;
import ch.unizh.ifi.ailab.tests.MockSuitcase;
import ch.unizh.ifi.ailab.utils.Utils;

/**
 * @author hans jaeckle jaeckle@gmail.com
 * 
 */
public class Gui extends JFrame implements ActionListener, KeyListener,
		WindowListener {

	private static final long serialVersionUID = 3124746727426856155L;

	private JFrame mainFrame = this;

	private JTabbedPane mainTabPanel = null;

	private JPanel mainPanel = null;

	private JPanel steeringPanel = null;

	private JPanel editorPanel = null;

	private ImagePanel myImagePanel = null;

	private JLabel descriptionLabel1 = null;

	private JLabel descriptionLabel2 = null;

	private JLabel descriptionLabel3 = null;

	private JButton buttonUp, buttonDown, buttonLeft, buttonRight, buttonStop,
			buttonKiMode, buttonStartSuit, buttonStartCam;

	private JMenuBar menuBar;

	private JMenu menuFile, menuSuit, menuCam, menuAI, menuHelp, menuLocale;

	private JMenuItem itemLocaleEn, itemLocaleDe;

	private JMenuItem itemExit, itemMock, itemLoadConfig,
			itemLoadDefaultConfig, itemSaveConfig, itemEditConfig;

	private JMenuItem itemSuitStart, itemSuitStop, itemSuitRestart,
			itemSuitReset, itemSuitSwitchMode;

	private JMenuItem itemCamStart, itemCamStop, itemCamRestart, itemCamRecord;

	private JMenuItem itemAIMode1VectorSMC;

	private JMenuItem itemHelpInfo, itemHelpDoc;

	// die properties
	private static ProgramSettings myProp = null;

	// die lokalisierung
	private static LocalizationSettings localization = null;

	// der koffer
	private Suitcase suitcase = null;

	// die kamera
	private Camera myCam = null;

	// logging
	private Logger myLog = Logger.getLogger(Gui.class);

	/**
	 * konstruktor methode
	 */
	public Gui() {
		myLog.debug("gui: initialisiere gui.");

		// apple speziefisch:
		if (System.getProperty("mrj.version") != null) {
			System.setProperty("apple.laf.useScreenMenuBar", "true");
			System.setProperty(
					"com.apple.mrj.application.apple.menu.about.name",
					"Null15 AI Control");
		}

		myProp = ProgramSettings.getProgramSettings();
		localization = LocalizationSettings.getLocalizationSettings();
		String localizationFilePath = new String(Utils.path(myProp
				.getProperty("path.conf"), "localization_"
				+ myProp.getProperty("defaultLocale") + ".prop"));
		File localizationFile = new File(localizationFilePath);
		if (localizationFile.exists()) {
			try {
				myLog.debug("gui: versuche lokalisierung zu laden: "
						+ localizationFile.toString());
				localization.loadFromXML(new FileInputStream(localizationFile));
			} catch (InvalidPropertiesFormatException e) {
				myLog.error("gui2007: fehler im properties file: "
						+ e.toString());
			} catch (FileNotFoundException e) {
				myLog.error("gui2007: properties file nicht gefunden: "
						+ e.toString());
			} catch (IOException e) {
				myLog.error("gui2007: io fehler: " + e.toString());
			}
		} else {
			myLog.error("konnte gewünschte lokalisierung nicht finden: "
					+ localizationFile);
			localizationFile = new File(Utils.path(myProp
					.getProperty("path.conf"), "localization_default.prop"));
			if (localizationFile.exists()) {
				try {
					localization.loadFromXML(new FileInputStream(
							localizationFile));
					myLog.debug("gui: lokalisierung geladen: "
							+ localizationFile.toString());
				} catch (InvalidPropertiesFormatException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				myLog.debug("gui: lade default lokalisierung.");
			} else {
				myLog.error("gui: konnte keine lokalisierung laden. default: "
						+ localizationFile);
			}
		}
		myCam = new Camera();
		myImagePanel = myCam.getImagePanel();

		createGui();

		mainFrame.setVisible(true);
	}

	private void createGui() {
		mainFrame.setResizable(true);
		mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		mainFrame.setTitle(localization.getProperty("loc-Gui-mainFrameTitle"));
		mainFrame.addWindowListener(this);

		descriptionLabel1 = new JLabel(" ");
		descriptionLabel2 = new JLabel(" ");
		descriptionLabel3 = new JLabel(" ");

		createMenu();
		mainFrame.setJMenuBar(menuBar);
		mainPanel = new JPanel(new GridBagLayout());
		mainTabPanel = new JTabbedPane();
		steeringPanel = new JPanel(new GridBagLayout());

		GridBagConstraints c = new GridBagConstraints();

		c.ipadx = 5;
		c.ipady = 5;
		c.gridx = 0;
		c.gridy = 1;
		c.anchor = GridBagConstraints.FIRST_LINE_START;

		c.gridx = 0;
		c.gridy = 2;
		c.anchor = GridBagConstraints.CENTER;
		mainPanel.add(myImagePanel, c);

		c.gridx = 1;
		c.gridy = 2;
		c.anchor = GridBagConstraints.PAGE_END;
		mainPanel.add(steeringPanel, c);

		c.gridx = 0;
		c.gridy = 3;
		c.gridwidth = 2;

		mainTabPanel.addTab(localization.getProperty("loc-Gui-mainPanel"),
				mainPanel);

		mainFrame.getContentPane().add(mainTabPanel);

		createButtons();
		updateLabels();
		mainFrame.pack();
	}

	/**
	 * createMenu methode zum erzeugen des menus
	 */
	private void createMenu() {
		// menu aufbauen
		menuBar = new JMenuBar();

		menuFile = new JMenu(localization.getProperty("loc-Gui-menuFile"));
		menuSuit = new JMenu(localization.getProperty("loc-Gui-menuSuit"));
		menuCam = new JMenu(localization.getProperty("loc-Gui-menuCam"));
		menuAI = new JMenu(localization.getProperty("loc-Gui-menuAI"));
		menuHelp = new JMenu(localization.getProperty("loc-Gui-menuHelp"));
		menuLocale = new JMenu(localization.getProperty("loc-Gui-menuLocale"));

		itemMock = new JMenuItem(localization.getProperty("loc-Gui-itemMock"));
		itemLoadDefaultConfig = new JMenuItem(localization
				.getProperty("loc-Gui-itemLoadDefaultConfig"));
		itemLoadConfig = new JMenuItem(localization
				.getProperty("loc-Gui-itemLoadConfig"));
		itemSaveConfig = new JMenuItem(localization
				.getProperty("loc-Gui-itemSaveConfig"));
		itemEditConfig = new JMenuItem(localization
				.getProperty("loc-Gui-itemEditConfig"));
		itemExit = new JMenuItem(localization.getProperty("loc-Gui-itemExit"));
		itemSuitStart = new JMenuItem(localization
				.getProperty("loc-Gui-itemSuitStart"));
		itemSuitStop = new JMenuItem(localization
				.getProperty("loc-Gui-itemSuitStop"));
		itemSuitRestart = new JMenuItem(localization
				.getProperty("loc-Gui-itemSuitRestart"));
		itemSuitReset = new JMenuItem(localization
				.getProperty("loc-Gui-itemSuitReset"));
		itemSuitSwitchMode = new JMenuItem(localization
				.getProperty("loc-Gui-itemSuitSwitchMode"));
		itemCamStart = new JMenuItem(localization
				.getProperty("loc-Gui-itemCamStart"));
		itemCamStop = new JMenuItem(localization
				.getProperty("loc-Gui-itemCamStop"));
		itemCamRestart = new JMenuItem(localization
				.getProperty("loc-Gui-itemCamRestart"));
		itemCamRecord = new JMenuItem(localization
				.getProperty("loc-Gui-itemCamRecord"));
		itemAIMode1VectorSMC = new JMenuItem(localization
				.getProperty("loc-Gui-itemAIMode1VectorSMC"));
		itemHelpInfo = new JMenuItem(localization
				.getProperty("loc-Gui-itemHelpInfo"));
		itemHelpDoc = new JMenuItem(localization
				.getProperty("loc-Gui-itemHelpDoc"));
		itemLocaleDe = new JMenuItem(localization
				.getProperty("loc-Gui-itemLocaleDe"));
		itemLocaleEn = new JMenuItem(localization
				.getProperty("loc-Gui-itemLocaleEn"));

		menuLocale.add(itemLocaleDe);
		menuLocale.add(itemLocaleEn);

		menuFile.add(itemMock);
		menuFile.addSeparator();
		menuFile.add(menuLocale);
		menuFile.addSeparator();
		menuFile.add(itemSaveConfig);
		menuFile.add(itemEditConfig);
		menuFile.addSeparator();
		menuFile.add(itemLoadDefaultConfig);
		menuFile.add(itemLoadConfig);
		menuFile.addSeparator();
		menuFile.add(itemExit);

		menuSuit.add(itemSuitStart);
		menuSuit.add(itemSuitStop);
		menuSuit.add(itemSuitRestart);
		menuSuit.add(itemSuitReset);
		menuSuit.addSeparator();
		menuSuit.add(itemSuitSwitchMode);

		menuCam.add(itemCamStart);
		menuCam.add(itemCamStop);
		menuCam.add(itemCamRestart);
		menuCam.addSeparator();
		menuCam.add(itemCamRecord);

		menuAI.add(itemAIMode1VectorSMC);

		menuHelp.add(itemHelpInfo);
		menuHelp.addSeparator();
		menuHelp.add(itemHelpDoc);

		menuBar.add(menuFile);
		menuBar.add(menuSuit);
		menuBar.add(menuCam);
		menuBar.add(menuAI);
		menuBar.add(menuHelp);

		itemExit.addActionListener(this);
		itemMock.addActionListener(this);
		itemLoadConfig.addActionListener(this);
		itemLoadDefaultConfig.addActionListener(this);
		itemEditConfig.addActionListener(this);
		itemSaveConfig.addActionListener(this);
		itemSuitStart.addActionListener(this);
		itemSuitStop.addActionListener(this);
		itemSuitRestart.addActionListener(this);
		itemSuitReset.addActionListener(this);
		itemSuitSwitchMode.addActionListener(this);
		itemCamStart.addActionListener(this);
		itemCamStop.addActionListener(this);
		itemCamRestart.addActionListener(this);
		itemCamRecord.addActionListener(this);
		itemAIMode1VectorSMC.addActionListener(this);
		itemHelpInfo.addActionListener(this);
		itemHelpDoc.addActionListener(this);
		itemLocaleDe.addActionListener(this);
		itemLocaleEn.addActionListener(this);

		itemExit.setActionCommand("exit");
		itemMock.setActionCommand("mockSuitcase");
		itemLoadConfig.setActionCommand("loadConfig");
		itemLoadDefaultConfig.setActionCommand("defaultConfig");
		itemSaveConfig.setActionCommand("saveConfig");
		itemEditConfig.setActionCommand("editConfig");
		itemSuitStart.setActionCommand("StartSuit");
		itemSuitStop.setActionCommand("suitstop");
		itemSuitRestart.setActionCommand("suitrestart");
		itemSuitReset.setActionCommand("reset");
		itemSuitSwitchMode.setActionCommand("suitmode");
		itemCamStart.setActionCommand("StartCam");
		itemCamStop.setActionCommand("camstop");
		itemCamRestart.setActionCommand("camrestart");
		itemCamRecord.setActionCommand("camrecord");
		itemAIMode1VectorSMC.setActionCommand("kivectorsmc");
		itemHelpInfo.setActionCommand("helpinfo");
		itemHelpDoc.setActionCommand("helpdoc");
		itemLocaleDe.setActionCommand("localeDe");
		itemLocaleEn.setActionCommand("localeEn");
	}

	/**
	 * createButtons methode zum erzeugen der steuerungsknoepfe
	 */
	private void createButtons() {
		buttonUp = new JButton(localization.getProperty("loc-Gui-buttonUp"));
		buttonUp.setActionCommand("MoveForward");
		buttonUp.addKeyListener(this);

		buttonDown = new JButton(localization.getProperty("loc-Gui-buttonDown"));
		buttonDown.setActionCommand("MoveBack");
		buttonDown.addKeyListener(this);

		buttonLeft = new JButton(localization.getProperty("loc-Gui-buttonLeft"));
		buttonLeft.setActionCommand("TurnLeft");
		buttonLeft.addKeyListener(this);

		buttonRight = new JButton(localization
				.getProperty("loc-Gui-buttonRight"));
		buttonRight.setActionCommand("TurnRight");
		buttonRight.addKeyListener(this);

		buttonStop = new JButton(localization.getProperty("loc-Gui-buttonStop"));
		buttonStop.setActionCommand("FullStop");
		buttonStop.addKeyListener(this);

		buttonKiMode = new JButton(localization
				.getProperty("loc-Gui-buttonKiMode"));
		buttonKiMode.setActionCommand("SwitchKI");
		buttonKiMode.addKeyListener(this);

		buttonStartSuit = new JButton(localization
				.getProperty("loc-Gui-buttonStartSuit"));
		buttonStartSuit.setActionCommand("StartSuit");
		buttonStartSuit.addKeyListener(this);

		buttonStartCam = new JButton(localization
				.getProperty("loc-Gui-buttonStartCam"));
		buttonStartCam.setActionCommand("StartCam");
		buttonStartCam.addKeyListener(this);

		buttonUp.addActionListener(this);
		buttonDown.addActionListener(this);
		buttonLeft.addActionListener(this);
		buttonRight.addActionListener(this);
		buttonStop.addActionListener(this);
		buttonKiMode.addActionListener(this);
		buttonStartSuit.addActionListener(this);
		buttonStartCam.addActionListener(this);

		GridBagConstraints c = new GridBagConstraints();
		c.insets = new Insets(2, 2, 2, 2);

		// placing the buttons
		c.gridx = 3;
		c.gridy = 4;
		steeringPanel.add(buttonUp, c);
		c.gridx = 2;
		c.gridy = 5;
		steeringPanel.add(buttonLeft, c);
		c.gridx = 3;
		steeringPanel.add(buttonKiMode, c);
		c.gridx = 4;
		steeringPanel.add(buttonRight, c);
		c.gridx = 3;
		c.gridy = 6;
		steeringPanel.add(buttonDown, c);
		c.gridx = 3;
		c.gridy = 7;
		steeringPanel.add(buttonStop, c);
		c.gridx = 2;
		c.gridy = 8;
		steeringPanel.add(buttonStartSuit, c);
		c.gridx = 4;
		c.gridy = 8;
		steeringPanel.add(buttonStartCam, c);

		JLabel xy = new JLabel("");
		c.gridx = 1;
		c.gridy = 3;
		steeringPanel.add(xy, c);

		c.anchor = GridBagConstraints.FIRST_LINE_START;
		c.gridwidth = 5;
		c.gridx = 0;
		c.gridy = 0;
		steeringPanel.add(descriptionLabel1, c);
		c.gridx = 0;
		c.gridy = 1;
		steeringPanel.add(descriptionLabel2, c);
		c.gridx = 0;
		c.gridy = 2;
		steeringPanel.add(descriptionLabel3, c);
	}

	/**
	 * switchKIMode methode zum umschalten des koffers zwischen fernsteuermodus
	 * und ki
	 * 
	 * @param mode
	 *            boolscher wert der sagt ob ki ein oder aus sein soll
	 */
	private void switchKIMode() {
		getSuitcase().setRemoteMode(!getSuitcase().getRemoteMode());
	}

	/**
	 * selbstsprechend
	 */
	private void goFaster() {
		getSuitcase().speedIncrease();
	}

	/**
	 * selbstsprechend
	 */
	private void stop() {
		getSuitcase().emergencyStop();
	}

	/**
	 * selbstsprechend
	 */
	private void goSlower() {
		getSuitcase().speedDecrease();
	}

	/**
	 * selbstsprechend
	 */
	private void turnRight() {
		getSuitcase().directionRight();
	}

	/**
	 * selbstsprechend
	 */
	private void turnLeft() {
		getSuitcase().directionLeft();
	}

	/**
	 * selbstsprechend
	 */
	private void startSuit() {
		getSuitcase().start();
	}

	private void stopSuit() {
		getSuitcase().stirb();
	}

	private Suitcase getSuitcase() {
		if (suitcase == null) {
			suitcase = new Suitcase();
		}
		return suitcase;
	}

	/**
	 * selbstsprechend
	 */
	private void startCam() {
		myCam.start();
	}

	private void stopCam() {
		myCam.stirb();
	}

	private void getMockSuitcase() {
		getSuitcase().stirb();
		suitcase = new MockSuitcase();
	}

	private void loadPropertyFile() {
		String fileName = "current_save.prop";
		File file = new File(Utils.path(System.getProperty("user.dir"), ("conf"
				+ System.getProperty("file.separator") + fileName)));
		JFileChooser chooser = new JFileChooser();
		chooser.setFileHidingEnabled(true);
		chooser.setFileFilter(new PropertyFileFilter());
		chooser.setCurrentDirectory(file);

		int returnVal = chooser.showOpenDialog(mainFrame);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			file = chooser.getSelectedFile();
			FileInputStream is = null;
			try {
				is = new FileInputStream(file);
				myProp.loadFromXML(is);

				myLog.info("gui: properties laden: abgeschlossen. "
						+ file.getName());

				descriptionLabel1.setText(localization
						.getProperty("loc-Gui-message-loadedProperties"));
				descriptionLabel2.setText(localization
						.getProperty("loc-Gui-message-newProperties")
						+ file.getName());
			} catch (InvalidPropertiesFormatException e) {
				myLog.error("gui: properties laden: fehlerhafte  datei.");
			} catch (FileNotFoundException e) {
				myLog.error("gui: properties laden: datei nicht vorhanden.");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				if (is != null) {
					try {
						is.close();
					} catch (IOException e) {
					}
				}
			}
		} else {
			myLog.debug("gui: property open command cancelled by user.");
		}

	}

	private void loadDefaultPropertyFile() {
		myProp.configDefaults();
	}

	private void savePropertyFile(File file) {
		FileOutputStream os = null;
		try {
			os = new FileOutputStream(file);
			String comment = "User Saved Properties";
			myProp.storeToXML(os, comment, myProp.getProperty("encoding"));
			myProp.setProperty("currentFile", file.getPath());
			myLog.info("gui: properties speichern: abgeschlossen.");
		} catch (NullPointerException e) {
			myLog
					.info("gui: properties speichern: abgebrochen "
							+ e.toString());
		} catch (FileNotFoundException e) {
			myLog
					.info("gui: properties speichern: abgebrochen "
							+ e.toString());
		} catch (IOException e) {
			myLog
					.info("gui: properties speichern: abgebrochen "
							+ e.toString());
		} finally {
			if (os != null) {
				try {
					os.close();
				} catch (IOException e) {
				}
			}
		}
	}

	private void editProperties() {
		if (editorPanel == null) {
		}
	}

	public void updateLabels() {
		if (suitcase == null) {
			descriptionLabel1.setText(localization
					.getProperty("loc-Gui-message-SuitcaseNotRunning"));
			descriptionLabel2.setText(" ");
			descriptionLabel3.setText(" ");
		} else {
			if (suitcase.getConnected()) {
				if (suitcase.getRemoteMode()) {
					descriptionLabel1.setText(localization
							.getProperty("loc-Gui-message-AIOut"));
					descriptionLabel2.setText(localization
							.getProperty("loc-Gui-message-Speed")
							+ suitcase.getCommand().getSpeed() + ".");
					descriptionLabel3.setText(localization
							.getProperty("loc-Gui-message-Direction")
							+ suitcase.getCommand().getDirection() + ".");
				} else {
					descriptionLabel1.setText(localization
							.getProperty("loc-Gui-message-AIOn"));
					descriptionLabel2.setText(localization
							.getProperty("loc-Gui-message-AIMode")
							+ suitcase.getRemoteMode());
					descriptionLabel3.setText(" ");
				}
			} else {
				descriptionLabel1.setText(localization
						.getProperty("loc-Gui-message-NoSuitcase"));
				descriptionLabel2.setText(" ");
				descriptionLabel3.setText(localization
						.getProperty("loc-Gui-message-Connecting"));
			}
		}
	}

	private void exitGui(int exitValue) {
		myLog.info("gui: exit null15 controlling application");
		System.exit(0);
	}

	private void closeGui() {
		mainFrame.setVisible(false);
	}

	private void openGui() {
		mainFrame.setVisible(true);
	}

	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void windowClosed(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void windowClosing(WindowEvent arg0) {
		// TODO Auto-generated method stub
		exitGui(0);
	}

	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	/**
	 * keyTyped methode fuer das KeyListener interface.
	 * 
	 * leer - wird nicht gebraucht.
	 */
	public void keyTyped(KeyEvent e) {
	}

	/**
	 * keyPressed methode fuer das KeyListener interface.
	 * 
	 * einstellungen f�r windows.
	 */
	public void keyPressed(KeyEvent e) {
		// TODO: in den properties das umstellen zwischen windows und mac
		// vereinfachen, bzw laptop und pc tastatur
		switch (e.getKeyCode()) {
		case KeyEvent.VK_UP:
			goFaster();
			break;
		case KeyEvent.VK_DOWN:
			goSlower();
			break;
		case KeyEvent.VK_LEFT:
			turnLeft();
			break;
		case KeyEvent.VK_RIGHT:
			turnRight();
			break;
		case KeyEvent.VK_SPACE:
		case KeyEvent.VK_ENTER:
		case KeyEvent.VK_HOME:
			stop();
			break;
		case KeyEvent.VK_END:
		case KeyEvent.VK_NUMPAD0:
			switchKIMode();
			break;
		default:
			break;
		}
		updateLabels();
	}

	/**
	 * keyReleased methode fuer das KeyListener interface.
	 * 
	 * leer - wird nicht gebraucht.
	 */
	public void keyReleased(KeyEvent e) {
	}

	/**
	 * actionPerformed methode fuer das ActionListener Interface
	 */
	public void actionPerformed(ActionEvent e) {
		if ("TurnLeft" == e.getActionCommand()) {
			turnLeft();
		} else if ("TurnRight" == e.getActionCommand()) {
			turnRight();
		} else if ("MoveForward" == e.getActionCommand()) {
			goFaster();
		} else if ("MoveBack" == e.getActionCommand()) {
			goSlower();
		} else if ("SwitchKI" == e.getActionCommand()) {
			this.switchKIMode();
		} else if ("FullStop" == e.getActionCommand()) {
			stop();
		} else if ("StartSuit" == e.getActionCommand()) {
			startSuit();
		} else if ("StartCam" == e.getActionCommand()) {
			startCam();
		} else if ("exit" == e.getActionCommand()) {
			exitGui(0);
		} else if ("mockSuitcase" == e.getActionCommand()) {
			getMockSuitcase();
		} else if ("loadConfig" == e.getActionCommand()) {
			loadPropertyFile();
		} else if ("defaultConfig" == e.getActionCommand()) {
			loadDefaultPropertyFile();
		} else if ("saveConfig" == e.getActionCommand()) {
			String overWriteMessage = " existiert bereits. Soll ueberschrieben werden?";
			String fileName = "current_save.prop";
			File file = new File(Utils.path(myProp.getProperty("path.conf"),
					fileName));
			JFileChooser chooser = new JFileChooser(file);
			chooser.setSelectedFile(file);
			chooser.setFileFilter(new PropertyFileFilter());
			boolean write = false;

			int returnVal = chooser.showSaveDialog(mainFrame);
			if (returnVal == JFileChooser.APPROVE_OPTION) {
				write = true;
				file = chooser.getSelectedFile();
				if (file.exists()) {
					if (JOptionPane.showConfirmDialog(mainFrame, file.getName()
							+ overWriteMessage, "überschreiben?",
							JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) {
						write = true;
					} else {
						write = false;
					}
				}
				if (write) {
					savePropertyFile(file);
				}
			}
		} else if ("editConfig" == e.getActionCommand()) {
			editProperties();
		} else if ("suitstop" == e.getActionCommand()) {
			stopSuit();
		} else if ("suitrestart" == e.getActionCommand()) {
		} else if ("reset" == e.getActionCommand()) {
		} else if ("suitmode" == e.getActionCommand()) {
		} else if ("camstop" == e.getActionCommand()) {
			stopCam();
		} else if ("camrestart" == e.getActionCommand()) {
		} else if ("camrecord" == e.getActionCommand()) {
		} else if ("helpinfo" == e.getActionCommand()) {
			JDialog dialog = new AboutDialog(mainFrame);
			dialog.setVisible(true);
		} else if ("helpdoc" == e.getActionCommand()) {
		} else if ("kivectorsmc" == e.getActionCommand()) {
		} else if ("localeDe" == e.getActionCommand()) {
			myProp.setProperty("defaultLocale", "de");
			File file = new File(Utils.path(myProp.getProperty("path.conf"),
					"current.prop"));
			savePropertyFile(file);
		} else if ("localeEn" == e.getActionCommand()) {
			myProp.setProperty("defaultLocale", "en");
			File file = new File(Utils.path(myProp.getProperty("path.conf"),
					"current.prop"));
			savePropertyFile(file);
		}
		updateLabels();
	}
}
